Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass State in as a reference #3

Closed
wants to merge 2 commits into from
Closed

Conversation

alsuren
Copy link
Owner

@alsuren alsuren commented Jan 21, 2020

No description provided.

H: (FnOnce(State) -> Fut) + RefUnwindSafe + Copy + Send + Sync + 'static,
Fut: Future<Output = HandlerResult> + Send + 'static,
H: (FnOnce(&'_ mut State) -> Fut) + RefUnwindSafe + Copy + Send + Sync + 'static,
Fut: Future<Output = HandlerResult> + Send,
Copy link
Owner Author

@alsuren alsuren May 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that you can't tie the lifetime of State to that of Fut, because it has no lifetime parameters, and therefore no way to specify the required higher-ranked lifetime bounds ( https://doc.rust-lang.org/reference/trait-bounds.html#higher-ranked-trait-bounds ). If I manage to work-around this issue then it should fix gotham-rs#431 . I am going to chase this up in the upstream rust repo here:
rust-lang/rust#45994

If we manage to fix this, I will also have a good solution to the ergonomics problems in tag1consulting/goose#22

There is a slightly more self-contained exploration of this issue here: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=63830174a65ea4adf45eb5b095f0ae9b

@mikeplus64
Copy link

Can the state parameter be a generic parameter of the state middleware, and mutability (or not) left entirely up to the user, by their choice (or not) of a mutable reference type like Arc<RwLock<...>>?

@alsuren
Copy link
Owner Author

alsuren commented Feb 4, 2024

Just closing some old PRs. Nothing to see here.

@alsuren alsuren closed this Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants